/**
 * 
 */
package spatial.geometry;

import java.awt.Polygon;
import java.awt.geom.Rectangle2D;
import java.util.Vector;

/**
 * @author Xiaohui
 * 
 */
public class MyPolygon extends Polygon {

	/**
	 * MyPolygon is almost same as Polygon in java awt Except that it has an id,
	 * and it implement the BasicShape interface to facilitate comparing with
	 * cells.
	 */
	private int id;

	// private Vector<Integer> xcoors;
	// private Vector<Integer> ycoors;
	public MyPolygon(int id, int[] xs, int[] ys) {
		super(xs, ys, xs.length);
		// this.xcoors= new Vector<Integer> (xs.length);
		// this.ycoors= new Vector<Integer> (ys.length);
		this.id = id;
	}

	public MyPolygon() {
		super();
		this.id = 0;
	}

	public String toString() {
		StringBuilder s = new StringBuilder();
		s.append("[");
		for (int i = 0; i < this.npoints; i++) {
			s
					.append("(" + this.xpoints[i] + ", " + this.ypoints[i]
							+ ")" + " ");
		}
		s.append("]");
		return s.toString();
	}

	public int getID() {
		return id;
	}

	/**
	 * @return If the polygon contains the rectangle return true if all points
	 *         of the rectangle is inside the polygon.
	 */
//	@Override
//	public boolean contains(Rectangle2D r) {
//		double x = r.getX();
//		double y = r.getY();
//		double w = r.getWidth();
//		double h = r.getHeight();
//		boolean b1 = this.contains(x, y);
//		boolean b2 = this.contains(x + w, y);
//		boolean b3 = this.contains(x, y + h);
//		boolean b4 = this.contains(x + w, y + h);
//		System.out.println("b1"+b1);
//		System.out.println("b2"+b2);
//		System.out.println("contain0,4"+this.contains(4,0));
//		System.out.println("b3"+b3);
//		System.out.println("b4"+b4);
//		System.out.println("contain4,4"+this.contains(4,4));
//		return this.contains(x, y) && this.contains(x + w, y)
//				&& this.contains(x, y + h) && this.contains(x + w, y + h);
//
//	}

}
